import { fileURLToPath, URL } from 'node:url'

import { ConfigEnv, defineConfig, loadEnv, UserConfig } from 'vite'
import { getPluginsList } from './build/plugins'
import { wrapperEnv } from './build/utils'
// https://vite.dev/config/
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
  const root = process.cwd()
  const { VITE_APP_CONSOLE } = wrapperEnv(loadEnv(mode, root))
  console.log(
    '%c [ VITE_APP_CONSOLE ]-10',
    'font-size:13px; background:pink; color:#bf2c9f;',
    VITE_APP_CONSOLE
  )
  return {
    plugins: getPluginsList(),
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      headers: {
        'Access-Control-Allow-Origin': '*'
      },
      proxy: {
        '^/api': {
          target: 'http://example.com'
        }
      }
    }
  }
})
